
package com.bee.common.web.aspect;

import com.bee.common.core.result.Result;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
import org.springframework.validation.BindingResult;


@Component
@Aspect
public class ValidateAspect {

     @Around(value = "execution(public * com.bee..*.controller..*.*(..)) && args(..,bindingResult)" )
     public Object around(ProceedingJoinPoint joinPoint, BindingResult bindingResult) throws Throwable {
    	 Object result=joinPoint.proceed();
		 if(bindingResult.hasErrors()){
			 return Result.fail(bindingResult.getAllErrors().get(0).getDefaultMessage());
		 }
		return result;
    }	
}